package com.person.leetcode.editor.cn;

/**
  * 14.最长公共前缀
  * 2023-02-15 15:48:12
**/
public class Sequence_0014_LongestCommonPrefix {
    public static void main(String[] args) {
        Solution solution = new Sequence_0014_LongestCommonPrefix().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String longestCommonPrefix(String[] strs) {
        StringBuilder ans = new StringBuilder();
        String flagStr = strs[0];
        for (int i = 0; i < flagStr.length(); i++) {
            char c = flagStr.charAt(i);
            int j = 1;
            for (; j < strs.length; j++) {
                if (i>= strs[j].length() || c != strs[j].charAt(i)) return ans.toString();
            }
            if (j == strs.length){
                ans.append(c);
            }
        }
        return ans.toString();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}